from peewee import MySQLDatabase

def peewee_mysql(database_name='python', user='root', password='123456', host='localhost', port=3308):
    """
    返回 Peewee 的 MySQLDatabase 实例
    """
    try:
        db = MySQLDatabase(
            database_name,
            user=user,
            password=password,
            host=host,
            port=int(port)  # 注意转换成 int
        )
        # 检查是否连接成功
        db.connect()
        return db
    except Exception as e:
        print(f"❌ 数据库连接失败: {e}")
        return None
